package logic_task_log

import (
	v1 "Sailor/app/Sailor-console-server/api/api_task_log/v1"
	"Sailor/app/Sailor-console-server/internal/dao"
	"Sailor/app/Sailor-console-server/internal/model/entity"
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sTaskLog) LogicTaskLogList(ctx context.Context, req *v1.TaskLogListReq) (res *v1.TaskLogListRes, err error) {
	var taskLogs []entity.SysTaskLog
	var total int
	daoo := dao.SysTaskLog.Ctx(ctx).Page(req.Page, req.PageSize).Where(dao.SysTaskLog.Columns().TaskUuid, req.TaskUuid)
	if req.Status != "" {
		daoo.Where(dao.SysTaskLog.Columns().TaskStatus, req.Status)
	}
	err = daoo.ScanAndCount(&taskLogs, &total, true)
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("获取任务日志列表失败")
	}
	return &v1.TaskLogListRes{
		Page:     req.Page,
		PageSize: req.PageSize,
		Rows:     taskLogs,
		Total:    total,
	}, nil
}
